package net.xdclass.video.controller;

import net.xdclass.video.common.Result;
import net.xdclass.video.entity.Sheets;
import net.xdclass.video.service.SheetsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; // 确保导入 Collectors

@RestController
@RequestMapping("/apiOne/sheets")
public class SheetsController {

    @Autowired
    private SheetsService sheetsService;

    @GetMapping("/findAll")
    public Result findAll() {
        // 从服务层获取所有的 Sheets 数据
        List<Sheets> sheets = sheetsService.list();

        // 按类型分类
        Map<String, List<Sheets>> categorizedSheets = sheets.stream()
                .collect(Collectors.groupingBy(Sheets::getClassify));

        // 打印分类结果（调试用）
        System.out.println(categorizedSheets);

        // 返回成功结果
        return Result.success(categorizedSheets);
    }
}
